package com.dgh.school.service.impl;

import com.dgh.school.bean.Clerk;
import com.dgh.school.bean.Meeting;
import com.dgh.school.common.R;
import com.dgh.school.mapper.MeetingMapper;
import com.dgh.school.service.MeetingService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//会议业务层实现 （类）
@Service
public class MeetingServiceImpl implements MeetingService {

    //注入mapper对象
    @Autowired
    private MeetingMapper meetingMapper;

    @Override
    public List<Meeting> selectAll() throws Exception {
        List<Meeting> meetings = meetingMapper.selectAll();
        return meetings;
    }

    @Override
    public List<Meeting> selectById(int lid) throws Exception {
        List<Meeting> meetings = meetingMapper.selectById(lid);
        return meetings;
    }

    @Override
    public void addMeeting(Meeting m) throws Exception {
        meetingMapper.insertMeeting(m);
    }

    @Override
    public void updateMeeting(Meeting m) throws Exception {
        meetingMapper.updateMeeting(m);
    }

    @Override
    public void deleteMeeting(int mid) throws Exception {
        meetingMapper.deleteMeeting(mid);
    }

    @Override
    public R selectByPage(int pageNum, int pageSize) throws Exception {

        PageHelper.startPage(pageNum, pageSize);
        // 查询全部数据
        List<Meeting> meetings = meetingMapper.selectAll();
        // 借助分页助手，获得分页信息
        PageInfo<Meeting> pageInfo = new PageInfo<>(meetings);

        return R.ok().setDate("pageInfo", pageInfo);
    }
}
